<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setAttribute("basePath", basePath);
String jsonData= (String)request.getAttribute("jsonData");
String respondResultJson = (String)request.getAttribute("respondResultJson");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>解放军第三〇五医院</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" href="${basePath}static/css/basic.css"/>
	<link rel="stylesheet" href="${basePath}static/css/list.css"/>
	<script type="text/javascript" src="${basePath}static/js/plugs/jquery/jquery.min.js"></script>
	<script type="text/javascript" src="${basePath}assets/layer/layer.js"></script>
<%-- 	<link rel="stylesheet" href="${basePath}static/js/plugs/bootstrap/css/bootstrap.css"/>
	<script type="text/javascript" src="${basePath}static/js/plugs/bootstrap/js/bootstrap.js"></script> --%>
	<script type="text/javascript" src="${basePath}static/js/plugs/My97DatePicker/WdatePicker.js"></script>
  	
  </head>
  
  <body>
  	<input type="hidden" id="basePath" value="${basePath }">
    <form action="${basePath }export305/queryExportMedicalVisitForm" id="queryForm" method="get">
    	<table width="100%" cellspacing="0" border="0" cellpadding="0">
		<tbody>
			
			<tr>
				<td class="tdLabel_7">ID号</td>
				<td class="tdLabel_8">
					<input id="patientId" name="patientId" type="text" value=""  onchange="scanBarCodeQuery(this)"  class="dltxt01" /> 
					<!-- <input type="hidden" id="mrId" name="mrId"> -->
					<!-- <input type="hidden" id="visitNumber" name="visitNumber"> -->
					<%-- <input type="text" id="patientId" name="patientId" value="${patientId}"> --%>
				</td>
				<td class="tdLabel_7">住院次数</td>
				<td class="tdLabel_8">
					<%-- <c:if test="${not empty mrId and not empty visitNumber}">
						${ mrId}-${ visitNumber}
					</c:if> --%>
					<input type="text" id="visitNum" name="visitNum" value="${visitNum}">
				</td>
				<td class="tdLabel_7">出院日期</td>
				<td class="tdLabel_8"><input type="text" name="outHospitalStartDate"
					class="input_box" style="width:40%"
					value="${outHospitalStartDate}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})">
					&nbsp;&nbsp;-&nbsp;&nbsp;
					<input type="text" name="outHospitalEndDate"
					class="input_box" style="width:40%"
					value="${outHospitalEndDate}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				</td>
				
			</tr>
			<tr>
				<td align="left" colspan="6" class="dark">
					<div style="float:right">
						<input type="button" onclick="queryFormSubmit()" value="查询" class="btn">&nbsp;
					</div></td>
			</tr>
		</tbody>
	</table>
    </form>
    <form action="${basePath}export305/exportMedicalHospitalRecordByMrIdAndVisitNumber" method="post" id="portForm">
    	<input type="hidden" name="outHospitalStartDate" value="${outHospitalStartDate}"/>
		<input type="hidden" name="outHospitalEndDate" value="${outHospitalEndDate}">
		<input type="hidden" name="mrId">
		<input type="hidden" name="visitNumber">
		
		<input type="hidden"  name="patientId" value="${patientId}">
		<input type="hidden"  name="visitNum" value="${visitNum}">
    </form>
    <table width="100%" cellspacing="0" border="0" cellpadding="0" id="hispitalVisitTable">
    	<thead>
    		<tr>
    			<td class="tdLabel_4">ID号</td>
    			<td class="tdLabel_4">ID号</td>
    			<td class="tdLabel_4">姓名</td>
    			<td class="tdLabel_4">性别</td>
    			<td class="tdLabel_4">出生日期</td>
    			<td class="tdLabel_4">住院次数</td>
    			<td class="tdLabel_4">离院方式</td>
    			<td class="tdLabel_4">出院日期</td>
    			<td class="tdLabel_4">状态</td>
    			<td class="tdLabel_4">操作</td>
    			<td class="tdLabel_4">勾选</td>
    		</tr>
    	</thead>
		<tbody>
			
		</tbody>
	</table>
	<div style="display: none;">
		<table width="100%" cellspacing="0" border="0" cellpadding="0">
			<tbody>
				<tr id="hispitalVisitTrTemplate">
	    			<td class="tdLabel_8"><span class="id"></span></td>
	    			<td class="tdLabel_8"><span class="mrId"></span></td>
	    			<td class="tdLabel_8"><span class="name"></span></td>
	    			<td class="tdLabel_8"><span class="sex"></span></td>
	    			<td class="tdLabel_8"><span class="birthday"></span></td>
	    			<td class="tdLabel_8"><span class="visitNumber"></span></td>
	    			<td class="tdLabel_8"><span class="outHospitalType"></span></td>
	    			<td class="tdLabel_8"><span class="outHospitalDate"></span></td>
	    			<td class="tdLabel_8"><span class="state"></span></td>
	    			<td class="tdLabel_8"><button class="operate btn">提取</button></td>
	    			<td class="tdLabel_8"><input type="checkbox" name="onlyIds" checked="checked"/></td>
	    		</tr>
			</tbody>
		</table>
	</div>
  </body>
  <script type="text/javascript">
  
  	function queryFormSubmit(){
  		var basePath = $("#basePath").val();
  		$("#queryForm").attr("action",basePath + "export305/queryExportMedicalVisitForm");
  		$("#queryForm").submit();
  	}
  	
  	function scanBarFormSubmit(){
  		var basePath = $("#basePath").val();
  		$("#queryForm").attr("action",basePath + "export305/queryMedicalVisitScanForm")
  		$("#queryForm").submit();
  	}
  	
  	function clearScanBarCode(obj){
  		var currentObj = $(obj);
  		currentObj.val("");
  	}
  
  	function scanBarCodeQuery(obj){
  		var currentObj = $(obj);
  		var barCode = currentObj.val();
  		var barCodes = barCode.split("-");
  		
  		//alert(barCode);
  		if(barCodes.length == 2){
  			$("#patientId").val(barCodes[0]);
  			$("#visitNum").val(barCodes[1]);
  			$("#queryForm").submit();
  		}
  		
  	}
  	$(function(){
  		$("#patientId").focus();

		var jsonData= <%=jsonData%>;
		console.log(jsonData);
		var respondResultJson= <%=respondResultJson%>;
		console.log(respondResultJson);
		if(respondResultJson){
			if(respondResultJson.success){
				layer.msg(respondResultJson.stateMessage);
			}
		}
		var basePath = $("#basePath").val();
		for(var index in jsonData){
			var hospitalVisit = jsonData[index];
			var addTr=$("#hispitalVisitTrTemplate").clone();
			addTr.removeAttr("id");
			var a = addTr.find(".birthday");
			addTr.find(".birthday").html(hospitalVisit.BIRTHDAY);
			
			addTr.find(".id").html(hospitalVisit.ONLYID);
			addTr.find(".mrId").html(hospitalVisit.MRID);
			addTr.find(".name").html(hospitalVisit.PATIENTNAME);
			addTr.find(".sex").html(hospitalVisit.SEXNAME);
			addTr.find(".visitNumber").html(hospitalVisit.VISITNUMBER);
			addTr.find(".outHospitalType").html(hospitalVisit.OUTHOSPITALTYPENAME);
			if(hospitalVisit.OUTHOSPITALDATETIME){
				addTr.find(".outHospitalDate").html(hospitalVisit.OUTHOSPITALDATETIME.substring(0,10));
			}
			if(hospitalVisit.new_record =="1"){
				addTr.find(".operate").attr("mrId",hospitalVisit.MRID).attr("visitNumber",hospitalVisit.VISITNUMBER).attr("onclick","medicalRecordExport(this)");
				/* addTr.find(".operate").attr("href",basePath+"export305/exportMedicalHospitalRecordByMrIdAndVisitNumber?mrId="+hospitalVisit.MRID+"&visitNumber="+hospitalVisit.VISITNUMBER); */
				addTr.find("input[name='onlyIds']").val(hospitalVisit.ONLYID);
				addTr.find(".state").html("未收");
			}else{
				addTr.find(".operate").remove();
				addTr.find("input[name='onlyIds']").remove();
				addTr.find(".state").html("已收");
			}
			
			$("#hispitalVisitTable tbody").append(addTr);
			
		}
  	});
  	
	function medicalRecordExport(obj){
		var currentOjb = $(obj);
		

		$("input[name='mrId']").val(currentOjb.attr("mrId"));
		$("input[name='visitNumber']").val(currentOjb.attr("visitNumber"));
		$("#portForm").submit();
		
	}
  </script>
</html>
